package dao.manager;

import dao.DaoException;
import model.Manager;
import model.Reader;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ManagerDaoImpl implements ManagerDao {

    @Override
    public Manager managerLogin(String name, String password) throws DaoException {

        String sql = "SELECT * FROM manager WHERE name=? and password= ?";
        try (
                Connection connection = getConnection();
                PreparedStatement pstmt = connection.prepareStatement(sql);
        ) {
            pstmt.setString(1, name);
            pstmt.setString(2, password);
            try (ResultSet rst = pstmt.executeQuery()) {
                if (rst.next()) {
                    //进入这里表示有该用户。
                    Manager manager = new Manager();
                    manager.setId(rst.getInt("id"));
                    manager.setName(name);
                    return manager;
                }
            }

        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
        return null;


    }
}
